<template>
  <view class="list">
    <view class="goods">
      <view @click="goGoods(item)" v-for="(item,index) in gList" :key="index">
        <my-goods :item="item"></my-goods>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        queryObj: {
          query: '',
          pagenum: 1,
          pagesize: 10
        },
        gList: [],
        total: 0,
        isLoading: false
      };
    },
    onPullDownRefresh() {
      this.queryObj = {
        ...this.queryObj,
        pagenum: 1,
        pagesize: 10
      }
      this.total = 0
      this.getData(true)
    },
    onReachBottom() {
      if (this.queryObj.pagenum * this.queryObj.pagesize >= this.total) return uni.showToast({
        title: '🥺别拉了🥺',
        icon: "error"
      })

      if (this.isLoading) return
      this.queryObj.pagenum += 1
      this.getData()
    },
    onLoad(options) {
      this.queryObj.query = options.key
      this.getData()
    },
    methods: {
      // 点击进入商品详情
      goGoods(item) {
        uni.navigateTo({
          url: `/pages/goods_detail/main?goods_id=${item.goods_id}`
        })
      },
      async getData(boole) {
        this.isLoading = true
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/goods/search', this.queryObj).catch(err => err)
        if (res.meta.status !== 200) return uni.$showMsg
        // console.log(res);
        // this.gList = [...this.gList, ...res.message.goods]

        this.total = res.message.total
        if (boole) {
          uni.stopPullDownRefresh()
          uni.showToast({
            title: '😜刷新成功'
          })
          this.gList = res.message.goods
        } else {
          this.gList = [...this.gList, ...res.message.goods]
        }
        this.isLoading = false

      }
    }
  }
</script>

<style lang="scss">
  .list {}
</style>
